<template>
  <div>
    <el-table
      :data="tableData"
      border
      :height="$store.state.app.tableHeight"
      style="width: 100%;font-size:12px"
    >
      <el-table-column
        prop="anent_login_name"
        label="后台登录账号"
        width="100"
        align="center"
      />
      <el-table-column
        prop="anent_name"
        label="授权名"
        width="70"
        align="center"
      />
      <el-table-column
        prop="brand_phone"
        label="手机号"
        align="center"
        width="95"
      />
      <el-table-column
        prop="anent_login_name"
        label="微信号"
        align="center"
        width="100"
      />
      <el-table-column
        prop="people_card_num"
        label="身份证号"
        align="center"
        width="145"
      />
      <el-table-column
        prop="sheng"
        label="省份"
        align="center"
        width="60"
      />
      <el-table-column
        prop="shi"
        label="城市"
        align="center"
        width="70"
      />
      <el-table-column
        prop="qu"
        label="地区"
        align="center"
        width="70"
      />
      <el-table-column
        prop="address"
        label="地址"
        align="center"
      />
      <el-table-column
        label="授权品牌"
        width="70"
        align="center"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="checkImpower(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="resetAgent(scope.row)">修改</el-button>
          <confirm-info button-text="重置密码" :title="`是否确认将授权名为[ ${scope.row.anent_name}]的密码重置为[000000]?`" @onConfirm="resetPwd(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
    <reset-dialog ref="resetDialog" @reloadFun="reloadFun" />
  </div>
</template>

<script>
import resetDialog from './reset'
import confirmInfo from '@/components/DelConfirm'
import { TextToCode } from 'element-china-area-data'
import { resetAgentPwdApi } from '@/api/agent'
export default {
  components: {
    resetDialog,
    confirmInfo
  },
  props: {
    tableData: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
    }
  },
  methods: {
    checkImpower(row) {
      console.log(row)
      this.$router.push({
        name: 'agentImpower',
        params: { agent_id: row.id }
      })
    },
    resetAgent(row) {
      if (row.sheng === row.shi) {
        row.shi = '市辖区'
      }
      const sheng = TextToCode[row.sheng].code
      const shi = TextToCode[row.sheng][row.shi].code
      const qu = TextToCode[row.sheng][row.shi][row.qu].code
      const addressArr = [sheng, shi, qu]
      console.log(sheng, shi)
      this.$refs['resetDialog'].dialogShow = true
      this.$refs['resetDialog'].form.brand_phone = JSON.parse(JSON.stringify(row.brand_phone))
      this.$refs['resetDialog'].phone = JSON.parse(JSON.stringify(row.brand_phone))
      this.$refs['resetDialog'].form.sheng = JSON.parse(JSON.stringify(row.sheng))
      this.$refs['resetDialog'].form.shi = JSON.parse(JSON.stringify(row.shi))
      this.$refs['resetDialog'].form.qu = JSON.parse(JSON.stringify(row.qu))
      this.$refs['resetDialog'].form.address = JSON.parse(JSON.stringify(row.address))
      this.$refs['resetDialog'].form.anent_login_name = JSON.parse(JSON.stringify(row.anent_login_name))
      this.$refs['resetDialog'].form.addressArr = addressArr
      this.$refs['resetDialog'].form.id = row.id
    },
    reloadFun() {
      this.$emit('reloadFun')
    },
    resetPwd(row) {
      const data = {
        type: 1,
        id: row.id,
        anent_login_pass_word: '000000'
      }
      resetAgentPwdApi(data).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.$message.success('密码重置成功！')
        }
      })
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
